<?php
/**
 * Created by Zend Studio.
 * User: FDG348
 * Date: 2017/9/9
 * Time: 10:06
 */
namespace backend\models;

use yii\db\ActiveRecord;

class ContentArticleCategory extends ActiveRecord{
    const STATUS_ENABLE = 1;
    const STATUS_DISABLE = 0;
    
    public static function tableName(){
        return '{{%content_article_category}}';
    }
    
    public function rules(){
        return [
            ['use_flg','default','value'=>self::STATUS_DISABLE],
            ['is_display','default','value'=>self::STATUS_DISABLE],
            ['creator','getCreator']
        ];
    }
    
    /**
     * @获取创建人
     */
    public function getCreator(){
        $userInfo = \common\helps\tools::getloginUserInfo();
        if($userInfo){
            $userName = $userInfo->userName;
        }else{
            $userName = '';
        }
        return $userName;
    }
    
    public function getContentArticle()
    {
        return $this->hasMany(ContentArticle::className(), ['category_id'=>'id'])->where('j_content_article.use_flg=1 and j_content_article.is_release = 1');
    }
    
    /**
     * @param 获取底部导航
     * @return array|\yii\db\ActiveRecord[]
     */
    public static  function getBootNav(){
        return  self::find()
        ->joinWith('contentArticle')
        ->where([
            'j_content_article_category.use_flg'	=>self::USE_FLG_YES,
            'j_content_article_category.is_display'	=>self::STATUS_ENABLE,
        ])
        ->orderBy('j_content_article_category.sort asc')
        ->asArray()
        ->all();
    }
}